package scoreCard.LivestockJudging3C;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;

import org.json.JSONException;
import org.json.JSONObject;

import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.FacebookError;
import com.facebook.android.Util;

import scoreCard.LivestockJudging3C.R;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class LandingActivity extends Activity {
	protected Dialog mSplashDialog;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		// Main directory
		String extStorageDirectory = Environment.getExternalStorageDirectory()
				.toString();
		File newFile = new File(extStorageDirectory + "/3C");
		boolean success = newFile.mkdir();

		if (success) {
			// Temp folder
			File tempFold = new File(extStorageDirectory + "/3C/Temp");
			tempFold.mkdir();

			// Competition folder
			File compFold = new File(extStorageDirectory + "/3C/Competition");
			compFold.mkdir();
		}

		// initialize layout variables
		Button scoreButton = (Button) findViewById(R.id.scoreButton);
		Button recordButton = (Button) findViewById(R.id.recordButton);
		Button historyButton = (Button) findViewById(R.id.historyButton);
		Button shareButton = (Button) findViewById(R.id.shareButton);

		// set on click listeners
		scoreButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(LandingActivity.this,
						ScoreCalculatorActivity.class);
				startActivity(intent);
			}
		});
		recordButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(LandingActivity.this,
						VoiceRecorderActivity.class);
				startActivity(intent);
			}
		});
		historyButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(LandingActivity.this, HistoryActivity.class);
				startActivity(intent);
			}
		});
		shareButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(LandingActivity.this, ShareActivity.class);
				startActivity(intent);
			}
		});
	}
	
	public class SampleRequestListener implements RequestListener {

        public void onComplete(final String response, final Object state) {
            try {
                // process the response here: executed in background thread
                JSONObject json = Util.parseJson(response);
            
            } catch (JSONException e) {
            } catch (FacebookError e) {
            }
        }

		public void onIOException(IOException e, Object state) {
			
		}

		public void onFileNotFoundException(FileNotFoundException e,
				Object state) {
			
		}

		public void onMalformedURLException(MalformedURLException e,
				Object state) {
			
		}

		public void onFacebookError(FacebookError e, Object state) {
			
		}
	}
}